#ifndef M_SNAPCLIENT_H
#define M_SNAPCLIENT_H

#include "snap7.h"
#include <QtCore>

class M_snapClient : public QObject
{
    Q_OBJECT
public:
    explicit M_snapClient(QObject *parent = nullptr);

    bool connectTo(QString PLCPort);
    bool disConnect_();
    bool isOpen();

    bool hotStart();
    bool coldStart();
    bool stop();

    bool setDigitalOutput(int outputPort,bool flag);
    bool setDigitalOutputs(byte outputPorts);

    bool readDigitalOuput(int inputPort);
    byte readDigitalOutputs();

    bool readDigitalInput(int inputPort);
    byte readDigitalInputs();

    bool setAnalogInput(int inputPort,int value);

    word readAnalogInput(int inputPort);

private:
    TS7Client *client = new TS7Client;
    bool PlcOpenFlag =false;
    static inline uint16_t bswap_16_le_to_be(uint16_t le_value) {
        return (le_value >> 8) | ((le_value & 0x00FF) << 8);
    }

signals:
    void connectSucceed();
    void disconnectSucceed();
};

#endif // M_SNAPCLIENT_H
